﻿<UserControl x:Class="Chapters.Chapter03.ProgressBarAsProcessStages"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Chapter03="clr-namespace:FSharp.Chapter3;assembly=FSharpLibrary">
    <UserControl.Resources>

        <SolidColorBrush x:Key="NormalBrush"
                         Color="#eeeeee" />
        <LinearGradientBrush x:Key="SelectedStageBrush"
                             StartPoint="0,1"
                             EndPoint="0,0">
            <GradientStop Offset="0"
                          Color="#c21b00" />
            <GradientStop Offset="0.25"
                          Color="#ff6600" />
            <GradientStop Offset="0.5"
                          Color="#ea2804" />
            <GradientStop Offset="0.5"
                          Color="#e86a55" />
            <GradientStop Offset="0.75"
                          Color="#f49c8d" />
            <GradientStop Offset="1"
                          Color="#f1b9b0" />
        </LinearGradientBrush>

        <ControlTemplate x:Key="ProcessStageTemplate"
                         TargetType="ProgressBar">
            <ControlTemplate.Resources>
                <Style x:Key="{x:Type TextBlock}"
                       TargetType="{x:Type TextBlock}">
                    <Setter Property="Foreground"
                            Value="#c7c7c7" />
                </Style>
            </ControlTemplate.Resources>
            <Grid SnapsToDevicePixels="True">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="30" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="30" />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>

                <Rectangle x:Name="Stage1"
                           Fill="#eeeeee"
                           Stroke="#c7c7c7"
                           StrokeThickness="1"
                           RadiusX="5"
                           RadiusY="5"
                           Grid.Column="0"
                           Grid.Row="1" />
                <Rectangle x:Name="Stage2"
                           Fill="#eeeeee"
                           Stroke="#c7c7c7"
                           StrokeThickness="1"
                           RadiusX="5"
                           RadiusY="5"
                           Grid.Column="2"
                           Grid.Row="1" />

                <Rectangle x:Name="Stage3"
                           Fill="#eeeeee"
                           Stroke="#c7c7c7"
                           StrokeThickness="1"
                           RadiusX="5"
                           RadiusY="5"
                           Grid.Column="4"
                           Grid.Row="1" />
                <Rectangle x:Name="Stage4"
                           Fill="#eeeeee"
                           Stroke="#c7c7c7"
                           StrokeThickness="1"
                           RadiusX="5"
                           RadiusY="5"
                           Grid.Column="6"
                           Grid.Row="1" />
                <Rectangle x:Name="Stage5"
                           Fill="#eeeeee"
                           Stroke="#c7c7c7"
                           StrokeThickness="1"
                           RadiusX="5"
                           RadiusY="5"
                           Grid.Column="8"
                           Grid.Row="1" />

                <Rectangle Fill="#c7c7c7"
                           Grid.Column="1"
                           Grid.Row="1"
                           Height="1" />
                <Rectangle Fill="#c7c7c7"
                           Grid.Column="3"
                           Grid.Row="1"
                           Height="1" />
                <Rectangle Fill="#c7c7c7"
                           Grid.Column="5"
                           Grid.Row="1"
                           Height="1" />
                <Rectangle Fill="#c7c7c7"
                           Grid.Column="7"
                           Grid.Row="1"
                           Height="1" />

                <TextBlock Text="1"
                           Grid.Column="0"
                           Grid.Row="0"
                           TextAlignment="Center" />
                <TextBlock Text="2"
                           Grid.Column="2"
                           Grid.Row="0"
                           TextAlignment="Center" />
                <TextBlock Text="3"
                           Grid.Column="4"
                           Grid.Row="0"
                           TextAlignment="Center" />
                <TextBlock Text="4"
                           Grid.Column="6"
                           Grid.Row="0"
                           TextAlignment="Center" />
                <TextBlock Text="5"
                           Grid.Column="8"
                           Grid.Row="0"
                           TextAlignment="Center" />
            </Grid>

            <ControlTemplate.Triggers>
                <Trigger Property="Chapter03:ProcessStageHelper.ProcessStage"
                         Value="1">
                    <Setter Property="Fill"
                            Value="{StaticResource SelectedStageBrush}"
                            TargetName="Stage1" />
                    <Setter Property="Stroke"
                            Value="#bb2d00"
                            TargetName="Stage1" />
                </Trigger>
                <Trigger Property="Chapter03:ProcessStageHelper.ProcessStage"
                         Value="2">
                    <Setter Property="Fill"
                            Value="{StaticResource SelectedStageBrush}"
                            TargetName="Stage2" />
                    <Setter Property="Stroke"
                            Value="#bb2d00"
                            TargetName="Stage2" />
                </Trigger>
                <Trigger Property="Chapter03:ProcessStageHelper.ProcessStage"
                         Value="3">
                    <Setter Property="Fill"
                            Value="{StaticResource SelectedStageBrush}"
                            TargetName="Stage3" />
                    <Setter Property="Stroke"
                            Value="#bb2d00"
                            TargetName="Stage3" />

                </Trigger>
                <Trigger Property="Chapter03:ProcessStageHelper.ProcessStage"
                         Value="4">
                    <Setter Property="Fill"
                            Value="{StaticResource SelectedStageBrush}"
                            TargetName="Stage4" />
                    <Setter Property="Stroke"
                            Value="#bb2d00"
                            TargetName="Stage4" />

                </Trigger>
                <Trigger Property="Chapter03:ProcessStageHelper.ProcessStage"
                         Value="5">
                    <Setter Property="Fill"
                            Value="{StaticResource SelectedStageBrush}"
                            TargetName="Stage5" />
                    <Setter Property="Stroke"
                            Value="#bb2d00"
                            TargetName="Stage5" />

                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </UserControl.Resources>
    <DockPanel>
        <Slider x:Name="_slider"
                Minimum="0"
                Maximum="100"
                Value="0"
                Orientation="Horizontal"
                DockPanel.Dock="Bottom" />
        <TextBlock Text="{Binding Value, ElementName=_slider}"
                   DockPanel.Dock="Bottom" />
        <ProgressBar Template="{StaticResource ProcessStageTemplate}"
                     Margin="20"
                     Height="50"
                     Value="{Binding Value, ElementName=_slider}"
                     Chapter03:ProcessStageHelper.ProcessCompletion="{Binding Value, RelativeSource={RelativeSource Self}}" />
    </DockPanel>
</UserControl>
